<template>
  <div class="photoList">
    <van-tabs
      animated
      sticky
      offset-top="46px"
    >
      <van-tab
        v-for="item in titles"
        :key="item.id"
      >
        <template #title>
          <div @click="getImages(item.id)">
            {{ item.title }}
          </div>
        </template>
        <div
          class="img-box"
          v-if="images.length > 0"
        >
          <img
            v-for="item in images"
            :key="item.id"
            v-lazy="item.img_url"
            @click="goDetail('/home/photoinfo', item.id)"
          />
        </div>
        <div v-else>暂无数据</div>
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
export default {
  data() {
    return {
      titles: [],
      images: [],
    };
  },
  created() {
    this.getImgcategory();
    this.getImages(0);
  },
  methods: {
    async getImgcategory() {
      const res = await this.$http.getImgcategory();
      this.titles = res.data.message;
      this.titles.unshift({
        id: 0,
        title: '全部',
        isdel: '0',
      });
    },
    async getImages(id) {
      const res = await this.$http.getImages(id);
      this.images = res.data.message;
    },
  },
};
</script>
<style lang="scss" scoped>
.photoList {
  .img-box {
    img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
